import Vue from 'vue'
import App from './App.vue'
import router from './router'
import './plugins/element.js'
// 引入全局样式表
import './assets/css/global.css'
//导入字体图标
import './assets/fonts/iconfont.css'
//导入axios包
import axios from 'axios'
//设置默认请求地址
axios.defaults.baseURL = 'http://47.107.82.159:18081/'
    // 设置axios拦截器
// axios.interceptors.request.use(config => {
        
//     })
// 挂载原型对象
Vue.prototype.$http = axios



Vue.config.productionTip = false
    //注册时间过滤器
Vue.filter('dateFormat', function(date) {
    const dt = new Date(Number(date))
    const y = dt.getFullYear()
    const m = (dt.getMonth() + 1 + '').padStart(2, 0)
    const d = (dt.getDate() + '').padStart(2, 0)
    const hh = (dt.getHours() + '').padStart(2, 0)
    const mm = (dt.getMinutes() + '').padStart(2, 0)
    return `${y}-${m}-${d} ${hh}:${mm}`
})

router.beforeEach((to,from,next)=>{ 
    //如果是登录页，直接放行
      if(to.path === '/login')
        return next();
      
      //获取本地ID
      const userStatus = window.localStorage.getItem('userStatus');
    //没有ID值，强制跳转登录页面
      if(!userStatus)
        return next('/login');
      next();
    
    })

new Vue({
    router,
    render: h => h(App)
}).$mount('#app')